package com.huang.A01_case;

/**
 * 目标：
 * 完成数组拷贝
 */
public class Demo5 {
    public static void main(String[] args) {
        int[] arr = {11, 22, 33};
        int[] copy = copy(arr);
        print(copy);
    }

    public static void print(int[] copy) {
        System.out.print("[");
        for (int i = 0; i < copy.length; i++) {
            System.out.print(i == copy.length - 1 ? copy[i] : copy[i] + ", ");
        }
        System.out.println("]");
    }

    public static int[] copy(int[] arr) {
        //定义新数组
        int[] arr1 = new int[arr.length];
        //将原数组的值赋值给新数组
        for (int i = 0; i < arr.length; i++) {
            arr1[i] = arr[i];
        }
        return arr1;
    }
}